home *** CD-ROM | disk | FTP | other *** search
- Path: news.telepac.pt!usenet
- From: vortex@telepac.pt (VORTEX)
- Newsgroups: comp.lang.c
- Subject: Re: confusion between putchar and printf
- Date: Wed, 13 Mar 1996 10:14:18 GMT
- Organization: telepac
- Message-ID: <4i5lfv$ltv@vivaldi.telepac.pt>
- References: <4i1v2n$30o@news.azstarnet.com> <4i28j7INN65d@keats.ugrad.cs.ubc.ca>
- Reply-To: vortex@telepac.pt
- NNTP-Posting-Host: por1_p7.telepac.pt
- X-Newsreader: Forte Free Agent 1.0.82
-
- c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku) wrote:
-
- >In article <4i1v2n$30o@news.azstarnet.com>,
- >Howard Salmon <captarm@azstarnet.com> wrote:
- >>K & R (section 1.5) states that "putchar(c) prints the contents of the
- >>integer variable c as a character, usually on the screen".
- > ^^^^^^^^^^^^^^^^ ^^^^^^^^^
-
- >>Here's a small program that I wrote testing putchar. Why doesn't it
- >>compile?
- >>
- >>#include <stdio.h>
- >># define A "hello world!"
- >>
- >>main()
- >>{
- >> int c;
- >> c = A;
- >> putchar(A);
- >>}
-
- >Since when can you assign a string literal constant such as "hello world!" to
- >an _integer_ variable?
-
- >The C language has a concept of type. The values you assign to a variable
- >must have a type that is compatible with the variable's type.
-
- >Exactly what are you expecting this program to do? A single call to putchar is
- >incapable of emitting a string no matter what argument you give to it. It
- >prints a single character, exactly as K&R says. You can never get a single call
- >to putchar to place a string on the screen. Try this:
-
- >#include <stdio.h>
-
- >int main()
- >{
- > char *p = "hello, world!\n";
-
- > /* The string literal "hello, world\n" is stored in static memory.
- > The variable p is a character pointer which initially holds the
- > address of the character 'h'. */
-
- > while (*p) /* '*p' refers to the character pointed at by p */
- > /* we loop while this is not the zero character */
- > putchar(*p++); /* print that character, & increment p */
- > /* to point to the next character */
-
- > return 0; /* all C programs need to return an exit status */
- >}
- >--
-
-
-
-
- No they don'r
-
- Just star with void main(void) and you need to return any value
-
-